package net.hn.hnms.biz.safety.fire.Service;

import net.hn.hnms.biz.safety.fire.Dao.SensorMonitorDao;
import net.hn.hnms.biz.safety.fire.entity.SensorMonitor;
import net.hn.hnms.biz.safety.fire.unit.BaseMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author 智呈物联 nzw
 * @date 2022/7/28
 */
@Service
public class SensorMonitorService {

    @Autowired
    SensorMonitorDao sensorMonitorDao;

    public List<Map<String,Object>> findAll(){
        List<Map<String,Object>> maps = new ArrayList<>();
        List<SensorMonitor> list = sensorMonitorDao.findAll();
        for (SensorMonitor sensorMonitor:list){
            Map<String,Object> map = BaseMap.entityToMap(sensorMonitor);
            String state = sensorMonitor.getState();
            if (!state.contains("no")){
                String[] states = state.split("|");
                map.put("state",states);
            }else {
                String[] states  = new String[]{"no"};
                map.put("state",states);
            }
            maps.add(map);
        }
        return maps;
    }
}
